<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
use think\Db;
use app\index\model\School;
class Education extends Common
{  
    /*
     学历选择接口
     */
    public function resume(Request $request)
    {
        $type_id=Request::instance()->post('type_id','');//学历类型 1专科 2本科 3硕士 4博士
        if(empty($type_id)){
          return json(['state'=>'202','msg'=>'学历为空']);//
        }
         $school=Request::instance()->post('university','');//大学
        if($type_id==1){
          $where="properties='高职专科'";
          if(!empty($school)){
               $where=$where." and name".' '.'like'.' '."'".'%'.$school.'%'."'";
          }
          $result=School::college($where);
          if($result){
              return json($this->array_nonull(['state'=>'200','msg'=>'查询成功','result'=>$result]));
          }else{
              return json($this->array_nonull(['state'=>'201','msg'=>'查询内容不存在']));
          }
        }else{
          $where="properties='本科'";
           if(!empty($school)){
               $where=$where." and name".' '.'like'.' '."'".'%'.$school.'%'."'";
          }
          $result=School::regular($where);
          if($result){
              return json(['state'=>'200','msg'=>'查询成功','result'=>$result]);
          }else{
              return json(['state'=>'201','msg'=>'查询内容不存在']);
          }
        }
    }
    //编辑的学校选择接口
    public function school_edit(){
       $type_id=Request::instance()->post('type_id','');//学历类型 1专科 2本科 3硕士 4博士
       $uid=Request::instance()->post('uid','');//用户id
        if(empty($type_id) || empty($uid)){
          return json(['state'=>'202','msg'=>'参数不足']);//
        }
        if($type_id==1){
          $where="properties='高职专科'";
          $result= $collegeList=Db::name('school')
                 ->where($where) 
                   ->field('id as universityId,name as university')
                 ->select();
          if($result){
              return json($this->array_nonull(['state'=>'200','msg'=>'查询成功','result'=>$result]));
          }else{
              return json($this->array_nonull(['state'=>'201','msg'=>'查询内容不存在']));
          }
        }else{
          $where="properties='本科'";
          $result=Db::name('school')
                 ->where($where) 
                   ->field('id as universityId,name as university')
                 ->select();
          if($result){
              return json(['state'=>'200','msg'=>'查询成功','result'=>$result]);
          }else{
              return json(['state'=>'201','msg'=>'查询内容不存在']);
          }
        }
    }
    /*地区选择接口*/
    public function city(){
      $array=Db::table('tb_e_city')->field('cityId,cityName')->where(['parent_id'=>0])->select();
      foreach ($array as $key => $value) {
        $list=Db::table('tb_e_city')->field('cityId,cityName')->where(['parent_id'=>$value['cityId']])->select();
        $array[$key]['sons']=$list;
      }
     if($array){
      return json(['state'=>'200','msg'=>'查询成功','result'=>$array]);
     }else{
      return json(['state'=>'201','msg'=>'查询内容不存在']);
     }
    }
    /**
     * 城市切换接口
     */
    public function switCity(){

     $result= Db::name('city')->where('cityName','like','%市')->field('cityName')->select();
    if($result){
     $return=['state'=>'200','msg'=>'数据获取成功','result'=>$result]; 
    }else{
    $return=['state'=>'201','msg'=>'数据不存在']; 
   }
      return json($this->array_nonull($return));
    } 
    /*
    根据省返市的接口
     */
  public function citySel(){
    $cityId=input('cityId');//获取的省id
    if(empty($cityId)){   
     return json(['state'=>'202','msg'=>'参数不足']);
    } 
     $result= Db::name('city')->where('parent_id',$cityId)->field('cityName')->select();
    if($result){
     $return=['state'=>'200','msg'=>'数据获取成功','result'=>$result]; 
    }else{
    $return=['state'=>'201','msg'=>'数据不存在']; 
   }
      return json($this->array_nonull($return));
   }     
}
